<template>
	<view class="order-detail-content">
		<!-- address -->
		<AddressItem :use-path="1" :address="address"></AddressItem>
		<!-- baseData -->
		<BaseData :number="order.number"  :order-time="order.orderTime"  ></BaseData>
		<!-- PayMode -->
		<PayMode></PayMode>
		<!-- list -->
		<view class="list-wrap">
			<OrderItem :orderItem="order" :usePath="2" >
				<ListItem  v-for="item in order.orderDetailList" :key="item.id" :itemData="item"></ListItem>
			</OrderItem>
		</view>
		
		<!-- 底部功能 -->
		<Tool :goods-id="goodsId" :total-price="order.amount" ></Tool>
	</view>
</template>

<script>
	import ListItem from "./components/list-item.vue"
	import OrderItem from "./components/order-item.vue"
	import AddressItem from "../user/components/address_item.vue"
	import Tool from "./components/tool.vue"
	import BaseData from "./components/order_base_data.vue"
	import PayMode from "./components/pay-mode.vue"
	import { getAddressDefaultApi } from "@/http/address.js"
	import { getOrderDPayApi } from "@/http/order.js"
	
	
	export default {
		data() {
			return {
				goodsId:null,
				address:{
					id: null,
					name: "***先生",
					tel: "*********",
					area: "****  ****  ****",
					detail: "****************",
					isDefault:0
				},
				orderQuery:{
					orderId:null
				},
				order: {}
			}
		},
		components: {
			ListItem,
			OrderItem,
			AddressItem,
			Tool,
			BaseData,
			PayMode
		},
		onLoad(e){
			console.log(e);
			this.goodsId = e.id;
			this.getOrderDetail(e.id);
		},
		onShow() {
			this.getAddressDefault();
		},
		methods: {
			
			// 获取默认收货地址
			async getAddressDefault(){
				const res = await getAddressDefaultApi();
				if(!res) return;
				res.area =  `${res.provinceName} ${res.cityName} ${res.districtName}`
				this.address = res;
			},
			// 获取订单信息
			async getOrderDetail(id){
				const res = await getOrderDPayApi(id);
				
				
				if(!res){
					uni.showToast({
						title:"请先添加收货地址",
						icon:'none',
						duration:2000
					})
					setTimeout(()=>{
						uni.redirectTo({
							url:"/pages/user/address"
						})
					},2000)
				}else{
					this.order = res.data;
				}
				
			}
		}
	}
</script>

<style lang="less" scoped>
	.order-detail-content {
		background-color: #fbf9ec;
		min-height: 100vh;
		padding-top: 30rpx;
		
		.tab-wrap {
			position: fixed;
			width: 100%;
			z-index: 1000;
			// padding-bottom: 2;
		}

		.list-wrap {
			padding: 0 20rpx;
			padding-top: 15rpx;


		}
	}
</style>